package com.sky.controller.user;

import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersPaymentDTO;
import com.sky.dto.OrdersSubmitDTO;
import com.sky.dto.OrdersSubmitModifyDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderSubmitVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.lang.annotation.Target;

@RestController("userOrderController")
@RequestMapping("user/order")
@Api(tags = "用户提交订单")
@Slf4j
public class OrderController {

    @Autowired
    private OrderService orderService;

    @PostMapping("/submit")
    @ApiOperation("用户提交订单")
    public Result<OrderSubmitVO> submit(@RequestBody OrdersSubmitDTO ordersSubmitDTO){
        log.info("用户提交订单：{} ", ordersSubmitDTO);
        OrderSubmitVO orderSubmitVO = orderService.submitOrder(ordersSubmitDTO);
        return Result.success(orderSubmitVO);
    }

    @PutMapping("/payment")
    @ApiOperation("订单支付个人修改版")
    public Result<OrdersSubmitModifyDTO> payment(@RequestBody OrdersPaymentDTO ordersPaymentDTO){
        OrdersSubmitModifyDTO 	ordersSubmitModifyDTO=orderService.submitOrderModify(ordersPaymentDTO);
        return   Result.success(ordersSubmitModifyDTO);
    }

    /**
     * 用户端-历史订单查询
     * @param ordersPageQueryDTO
     * @return
     */
    @GetMapping("/historyOrders")
    @ApiOperation("用户端-查询历史订单")
    public Result<PageResult> getHistoryOrders(OrdersPageQueryDTO ordersPageQueryDTO){
        log.info("用户端-查询历史订单：{} ", ordersPageQueryDTO);
        PageResult pageResult = orderService.getHistoryOrders(ordersPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 用户端-查询订单详情
     * @param id
     * @return
     */
    @GetMapping("/orderDetail/{id}")
    @ApiOperation("用户端-查询订单详情")
    public Result<OrderVO> getOrderById(@PathVariable Long id){
        log.info("用户端-查询订单详情：{} ", id);
        OrderVO orderVO = orderService.getOrderById(id);
        return Result.success(orderVO);
    }

    /**
     * 用户端-取消订单
     * @param id
     * @return
     */
    @PutMapping("/cancel/{id}")
    @ApiOperation("用户端-取消订单")
    public Result cancel(@PathVariable Long id){
        log.info("用户端-取消订单：{} ", id);
        orderService.cancel(id);
        return Result.success();
    }

    /**
     * 用户端-再来一单
     * @param id
     * @return
     */
    @PostMapping("/repetition/{id}")
    @ApiOperation("用户端-再来一单")
    public Result repetition(@PathVariable Long id){
        log.info("用户端-再来一单：{} ", id);
        orderService.repetition(id);
        return Result.success();
    }

    /**
     * 用户端-订单催单
     * @param id
     * @return
     */
    @GetMapping("/reminder/{id}")
    @ApiOperation("用户端-订单催单")
    public Result reminder(@PathVariable("id") Long id){
        orderService.reminder(id);
        return Result.success();
    }
}
